package com.lagou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.dao.ResourceMapper;
import com.lagou.domain.Resource;
import com.lagou.domain.ResourceCategory;
import com.lagou.domain.ResourceVO;
import com.lagou.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    /**
     * 资源信息分页&条件查询
     *
     * @param resourceVO
     * @return
     */
    @Override
    public PageInfo<Resource> findAllResource(ResourceVO resourceVO) {

        PageHelper.startPage(resourceVO.getCurrentPage(), resourceVO.getPageSize());
        List<Resource> list = resourceMapper.findAllResource(resourceVO);
        return new PageInfo<>(list);
    }

    /**
     * 新增资源
     *
     * @param resource
     */
    @Override
    public void saveResource(Resource resource) {

        Date date = new Date();
        resource.setCreatedBy("system");
        resource.setCreatedTime(date);
        resource.setUpdatedBy("system");
        resource.setUpdatedTime(date);
        resourceMapper.saveResource(resource);
    }

    /**
     * 更新资源
     *
     * @param resource
     */
    @Override
    public void updateResource(Resource resource) {

        resource.setUpdatedTime(new Date());
        resource.setUpdatedBy("system");
        resourceMapper.updateResource(resource);
    }

    /**
     * 删除资源信息
     *
     * @param id 资源id
     * @return
     */
    @Override
    public void deleteResource(Integer id) {

        resourceMapper.deleteResource(id);
    }
}
